<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理员则测</title>
    <script src="/static/jquery-3.6.0.min.js"></script>
</head>
<body>
<div>
    <button type="button" id="gotoLogin">已有帐号，返回登录！</button><br>
    用&nbsp;户&nbsp;名：<input type="text" name="username"><br>
    密&nbsp;&nbsp;&nbsp;&nbsp;码 ：<input type="password" name="password"><br>
    确认密码：<input type="password" name="confirmPassword"><br>
    姓&nbsp;&nbsp;&nbsp;&nbsp;名：<input type="text" name="adminName"><br>
    <br>
    <button type="button" id="adminRegister">注册</button>
</div>
</body>
<script>
    $(function () {
        gotoLogin();
        register();
    });
    function gotoLogin(){
        $("#gotoLogin").click(function (){
            location.href="/admin/login";
        });
    }
    function register(){
        $("#adminRegister").click(function () {
            let username = $("[name=username]").val();
            let password = $("[name=password]").val();
            let confirmPassword = $("[name=confirmPassword]").val();
            let adminName = $("[name=adminName]").val();
            $.post("/admin/adminRegister", {
                "username": username,
                "password": password,
                "confirmPassword": confirmPassword,
                "adminName": adminName
            }, function (data) {
                console.log(data);
                let resData = JSON.parse(data);
                if (resData.resCode == 200) {
                    alert(resData.resMsg);
                    location.href="/admin/login";
                } else {
                    alert(resData.resMsg);
                }
            });
        });
    }
</script>
</html>